package com.yin.listener;

import org.springframework.context.ApplicationEvent;
import org.springframework.context.event.SmartApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import com.yin.entity.UserEntity;
import com.yin.event.UserRegisterEvent;
import com.yin.service.UserService;

/**
*@author LSY
*Time: 2018年12月28日上午11:03:24
*
*
*/
@Component
public class UserRegisterSendMailListener implements SmartApplicationListener{

	@Override
	@Async
	public void onApplicationEvent(ApplicationEvent event) {
		try {
			Thread.sleep(5000);
		} catch (Exception e) {
			// TODO: handle exception
		}
		UserRegisterEvent userEvent = (UserRegisterEvent) event;
		//获取注册用户对象
		UserEntity userEntity = userEvent.getUserEntity();
		//输出注册用户信息
		System.out.println("用户："+userEntity.getName()+"，注册成功，发送邮件通知。");
	}

	@Override
	public int getOrder() {
		// TODO Auto-generated method stub
		return 1;
	}

	@Override
	public boolean supportsEventType(Class<? extends ApplicationEvent> eventType) {
		// TODO Auto-generated method stub
		return eventType == UserRegisterEvent.class;
	}

	@Override
	public boolean supportsSourceType(Class<?> sourceType) {
		// TODO Auto-generated method stub
		return sourceType == UserService.class;
	}

}
